//脚本来初始化数据库中的数据
//启动指令npx ts-node src/db/seed.ts
import mongoose from 'mongoose';
import Enterprise from '../models/enterprise';
import { connectDB } from './connection';

const seedEnterprises = async () => {
  await connectDB();

  const enterprises = [
    {
      name: '企业A',
      details: '这是企业A的详细信息。',
      status: '正常运营',
      riskLevel: 79,
      serverCount: 10,
      activeServers: 8,
      expiredServers: 2,
    },
    {
      name: '企业B',
      details: '这是企业B的详细信息。',
      status: '高风险',
      riskLevel: 92,
      serverCount: 5,
      activeServers: 3,
      expiredServers: 2,
    },
    {
      name: '企业C',
      details: '这是企业C的详细信息。',
      status: '稳定运营',
      riskLevel: 45,
      serverCount: 15,
      activeServers: 14,
      expiredServers: 1,
    },
  ];

  try {
    await Enterprise.deleteMany(); // 清空旧数据
    await Enterprise.insertMany(enterprises); // 插入新数据
    console.log('企业数据初始化成功');
    process.exit(0);
  } catch (error) {
    console.error('企业数据初始化失败:', error);
    process.exit(1);
  }
};

seedEnterprises();